<%@ page contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib  uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib  uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<link href="../css/apps/contract/edit.css" rel="stylesheet" media="screen"  />
<script type="text/javascript" src="../scripts/apps/contract/edit.js"></script>
<div class="input-append">
  <input id="code"  type="text"  /><button class="btn"><i class="icon-share"></i></button>
</div>
<div>
  <label id="pname" class="label label-info">请输入产品代码查询</label>
</div> 
<div id="mt">
 
 
</div>
 
 
<script type="text/javascript">
 $(function(){
	 setAutoComplete("code");
 });

 function setAutoComplete(id) {
     var obj = $("#"+id);
 	obj.autocomplete({
 		minLength : 3,
 		source : function(request, response) {
 			var term = request.term;
 			$.getJSON(
 					"product/product!searchall", 
 					{"term" : term}, 
 					function(data) {
 						response(data);
 					}							
 			);
 		},
 		focus : function(event, ui) {
 			obj.val(ui.item.code);
 			return false;
 		},
 		select : function(event, ui) {
 			obj.val(ui.item.code);	
 			$("#pname").text(ui.item.name);
 			searchContract(ui.item.code);
 			return false;
 		}

 	})
 	.data("autocomplete")._renderItem = function(ul, item) {
 		return $("<li></li>").data("item.autocomplete", item).append(
 				"<a>" + item.code + "|" + item.name + "</a>").appendTo(ul);
 	};
 }
 
 
 function searchContract(code){
	 $("#mt").load('contract/contract!contractsincode?product.code='+code);
 }
 </script>